<?php
declare(strict_types = 1);
namespace App\Controller\Api;

use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use App\Controller\AbstractController;
use App\Service\Code\Normal;
use App\Service\OrderLogisticService;
use App\Service\AppService\SystemCacheConfigService;

/**
 * @Controller(prefix="/LogisticService")
 * 
 * @author chenyun
 */
class OrderLogisticController extends AbstractController
{

    protected $classPath = "App\\Service\\OrderLogisticService\\";

    /**
     * @RequestMapping(path="QueryLogistic", methods="post")
     * 
     * @return string[]
     */
    public function queryLogistic(RequestInterface $request)
    {
        $parameters = $request->post();
        if (empty($parameters["express_sn"])) {
            return Normal::returnCode(Normal::FAIL, 'express_sn不能为空！');
        }
        if (empty($parameters["express_type"])) {
            return Normal::returnCode(Normal::FAIL, 'express_type不能为空！');
        }
        
        $express_sn = $parameters["express_sn"];
        $express_type = $parameters["express_type"];
        
        //查询系统业务配置里面的数据
        $config = SystemCacheConfigService::instance()->getCacheInfoBySystemCode($express_type);
        if (empty($config)) {
            return Normal::returnCode(Normal::FAIL, '系统参数未配置！');
        }
        
        $parameters["apiBody"] = $config;
        $classPath = $this->classPath . $express_type;
        if (!class_exists($classPath)) {
            return Normal::returnCode(Normal::FAIL, "{$classPath} not existed");
        }
        $container = container()->get($classPath);
        return $container->QueryLogisticByExpressSn($parameters);
    }
}
